package com.google.code.netcheckin.aprs;

import java.util.Arrays;

import com.google.code.netcheckin.io.Ascii;

public class AprsPacketConstants {

   public static final String CHAR_SET = "US_ASCII";

   public static final byte PKT_SEP_ADDRESSES	= Ascii.V_GREATER_THAN;
   public static final byte PKT_SEP_ADDRESS_PATH	= Ascii.V_COMMA;
   public static final byte PKT_SEP_DEST_PATH	= Ascii.V_COLON;
   public static final byte POS_TIME_NOMSG	= Ascii.V_SLASH;
   public static final byte POS_TIME_MSG	= Ascii.V_AT;
   public static final byte POS_NOTIME_MSG	= Ascii.V_EQUALS;
   public static final byte POS_NOTIME_NOMSG	= Ascii.V_EXCLAMATION_MARK;
  
   public static final byte MIC_E_CURR_REV0B	= 0x1c;
   public static final byte MIC_E_OLD_REV0B	= 0x1d;
   public static final byte MIC_E_CURRENT	= Ascii.V_BACK_QUOTE;
   public static final byte MIC_E_OLD		= Ascii.V_QUOTE;
  
   public static final byte RAW_GPS		= Ascii.V_DOLLAR;
  
   public static final byte MESSAGE		= Ascii.V_COLON;
   public static final byte OBJECT		= Ascii.V_SEMI_COLON;
   public static final byte ITEM		= Ascii.V_RIGHT_PARENTHESIS;
   public static final byte STATION_CAPAB	= Ascii.V_LESS_THAN;
   public static final byte QUERY		= Ascii.V_QUESTION;
   public static final byte TELEMETRY		= Ascii.V_T;
   public static final byte STATUS		= Ascii.V_GREATER_THAN;
  
   public static final byte WX_STN_ULTIMETER2K_A = Ascii.V_EXCLAMATION_MARK;
   public static final byte WX_STN_ULTIMETER2K_B = Ascii.V_DOLLAR;
   public static final byte WX_STN_PEET_BRO_UII_A	= Ascii.V_ASTERISK;
   public static final byte WX_STN_PEET_BRO_UII_B	= Ascii.V_NUMBER_SIGN;
   public static final byte WX_RPT_NOPOS	= Ascii.V_UNDERSCORE;
  
   public static final byte MAIDEN_HEAD_GRID	= Ascii.V_OPEN_BRACKET;
  
   public static final byte INVALID_OR_TEST	= Ascii.V_COMMA;
   public static final byte USER_DEFINED	= Ascii.V_BRACELEFT;
   public static final byte THIRD_PARTY		= Ascii.V_BRACERIGHT;

   public static final int TYPE_MSG		= 0;	// 1
   public static final int TYPE_MSG_ACK		= 0;	// 11
   public static final int TYPE_MSG_REJECT	= 0;	// 101
   public static final int TYPE_MSG_BULLETIN	= 0;	// 1001
   public static final int TYPE_MSG_BULL_GROUP	= 0;	// 10001
   public static final int TYPE_MSG_BULL_NWS	= 0;	// 100001
   public static final int TYPE_MSG_ANNOUNCEMENT	= 0;	// 1000001

   public static final int MASK_MSG_ACK_PART	= 0;
   public static final int MASK_MSG_REJ_PART	= 0;
   public static final int MASK_MSG_NWS_PART	= 0;
   public static final int MASK_MSG_BUL_PART	= 0;
   public static final int MASK_MSG_BULGRP_PART	= 0;
   public static final int MASK_MSG_ANN_PART	= 0;

   private static final byte[] TYPE_CODES = new byte[] {
    	MIC_E_CURR_REV0B,	// 28
    	MIC_E_OLD_REV0B,	// 29
    	POS_NOTIME_NOMSG,	// 33
    	WX_STN_PEET_BRO_UII_B,	// 35
    	RAW_GPS,		// 36
    	MIC_E_OLD,		// 39
    	ITEM,			// 41
    	WX_STN_PEET_BRO_UII_A,	// 42
    	INVALID_OR_TEST,	// 44
    	POS_TIME_NOMSG,		// 47
    	MESSAGE,		// 58
    	OBJECT,			// 59
    	STATION_CAPAB,		// 60
    	POS_NOTIME_MSG,		// 61
    	STATUS,			// 62
    	QUERY,			// 63
    	POS_TIME_MSG,		// 64
    	TELEMETRY,		// 84
    	MAIDEN_HEAD_GRID,	// 91
    	WX_RPT_NOPOS,		// 95
    	MIC_E_CURRENT,		// 96
    	USER_DEFINED,		// 123
    	THIRD_PARTY,		// 125
    };

   private static final String[] TYPE_NAMES = new String[] {
    "Mic-E Current (Rev 0 beta)",			// 28
    "Mic-E Old (Rev 0 beta)",				// 29
    "Position no time, no message OR WX Ultimeter 2K",	// 33
    "WX Peet Bros U II",				// 35
    "Raw GPS OR WX Ultimeter 2K",			// 36
    "Mic-e Old",					// 39
    "Item",						// 41
    "WX Peet Bros U II",				// 42
    "Invalid OR Test",					// 44
    "Postion, Time, No Message",			// 47
    "Message",						// 58
    "Object",						// 59
    "Station capabilities",				// 60
    "Position, no time, message",			// 61
    "Status",						// 62
    "Query",						// 63
    "Position, time, message",				// 64
    "Telemetry",					// 84
    "Maidenhead grid (obs)",				// 91
    "WX report, no position",				// 95
    "Mic-e current",					// 96
    "User defined",					// 123
    "Third party",					// 125
    };

    private static final String UNKNOWN_NAME = "unknown";

    public static final int getTypeCodeIndex(byte typecode) {
    	return Arrays.binarySearch(TYPE_CODES, typecode);
    }

    public static final String getTypeCodeName(byte typecode) {
    	int idx = getTypeCodeIndex(typecode);
	return idx > -1 ? getTypeCodeName(idx) : UNKNOWN_NAME;
    }
    
    public static final String getTypeCodeName(int codeidx) {
    	return TYPE_NAMES[codeidx];
    }

    public static final boolean isValidTypeCode(byte typecode) {
    	return -1 < getTypeCodeIndex(typecode);
    }
 
}
